home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Dynamo 4.2 for GSBug 1.5b10 / app.builder / build.a < prev    next >
Encoding:
Text File  |  1990-09-21  |  17.0 KB  |  927 lines  |  [TEXT/MPS ]

  1. ****************************************************************
  2. *                            *
  3. * buildapp.system                        *
  4. *                            *
  5. * Apple II 8-bit application builder and launcher.        *
  6. * Copyright (C) 1990 Apple Computer.            *
  7. * Version 4.2                        *
  8. *                            *
  9. * Written by Eric Soldan, Apple II DTS            *
  10. *                            *
  11. ****************************************************************
  12.  
  13.         include    ':dynamo.includes:sys.equ'
  14.         include    ':dynamo.includes:rt.h'
  15.         include    ':dynamo.includes:rt.macros'
  16.  
  17.         include    'app.config'
  18.         include    'm16.memory'
  19.  
  20. *********************************************
  21.  
  22. buildText    equ    $1600        ;Script file for building application.
  23.  
  24. fileName        equ    $1E00        ;filestr starts at $1E01.  Runtime
  25.                     ;strings aren't pascal-type.  There
  26.                     ;is a table called strlens that holds
  27.                     ;the lengths.  There is another table
  28.                     ;called maxstrlens that defines how
  29.                     ;big each string can get.
  30.                     ;To make a pascal string for ProDOS,
  31.                     ;the characters for the file name
  32.                     ;are placed in filestr.  Then the
  33.                     ;string length byte is copied to
  34.                     ;fileName, just in front of filestr.
  35.                     ;Now we have a regular pascal string
  36.                     ;for ProDOS.
  37. btFileName    equ    $1E80        ;This is the boot time file name.  If
  38.                     ;the user of BUILDAPP.SYSTEM wants to
  39.                     ;have his text in a file other than
  40.                     ;BUILDAPP.TEXT, or if the script file
  41.                     ;is in another directory, then he can
  42.                     ;place the pathname of the file into
  43.                     ;BUILDAPP.SYSTEM, starting at byte $2006.
  44.                     ;This is the standard way for launched
  45.                     ;programs to be given a pathname.  The
  46.                     ;default pathname in this location
  47.                     ;is BUILDAPP.TEXT. btpathstr starts at
  48.                     ;$1E81.  This string works like filestr,
  49.                     ;in reverse.  The pascal string is first
  50.                     ;copied into btFileName, and then the
  51.                     ;length byte is stored in the strlens
  52.                     ;table.  The reason for copying the
  53.                     ;string from $2006 is because this area
  54.                     ;will be written over, and if the user
  55.                     ;wants to re-run the program due to an
  56.                     ;error, this string would have been lost.
  57.  
  58. *********************************************
  59.  
  60. MLI        equ    $BF00        ;Various equates for ProDOS.
  61. paramCount    equ    $00
  62.  
  63. CREATE        equ    $C0
  64. create_pathname    equ    $01
  65. create_access    equ    $03
  66. create_filetype    equ    $04
  67. create_auxtype    equ    $05
  68. create_strgtype    equ    $07
  69. create_createdate    equ    $08
  70. create_createtime    equ    $0A
  71.  
  72. OPEN        equ    $C8
  73. open_pathname    equ    $01
  74. open_iobuffer    equ    $03
  75. open_refnum    equ    $05
  76.  
  77. READ        equ    $CA
  78. read_refnum    equ    $01
  79. read_databuffer    equ    $02
  80. read_reqcount    equ    $04
  81. read_transcount    equ    $06
  82.  
  83. WRITE        equ    $CB
  84. write_refnum    equ    $01
  85. write_databuffer    equ    $02
  86. write_reqcount    equ    $04
  87. write_transcount    equ     $06
  88.  
  89. SETEOF        equ    $D0
  90. setEOF_refnum    equ    $01
  91. setEOF_EOF    equ    $02
  92.  
  93. SETFILEINFO    equ    $C3
  94. setInfo_pathname    equ    $01
  95. setInfo_access    equ    $03
  96. setInfo_filetype    equ    $04
  97. setInfo_auxtype    equ    $05
  98. setInfo_nullfield    equ    $07
  99. setInfo_moddate    equ    $0A
  100. setInfo_modtime    equ    $0C
  101.  
  102. GETFILEINFO    equ    $C4
  103. getInfo_pathname    equ    $01
  104. getInfo_access    equ    $03
  105. getInfo_filetype    equ    $04
  106. getInfo_auxtype    equ    $05
  107. getInfo_strgtype    equ    $07
  108. getInfo_blksused    equ    $08
  109. getInfo_moddate    equ    $0A
  110. getInfo_modtime    equ    $0C
  111. getInfo_crdate    equ    $0E
  112. getInfo_crtime    equ    $10
  113.  
  114. CLOSE        equ    $CC
  115. close_refnum    equ    $01
  116.  
  117. QUIT        equ    $65
  118.  
  119. *********************************************
  120.  
  121. numstrings    equ    5
  122.  
  123. bffrstr        equ    0
  124. maxbffrstr    equ    127
  125. bffrstrloc    equ    $1D01
  126.  
  127. tempstr        equ    1
  128. maxtempstr    equ    127
  129. tempstrloc    equ    $1D81
  130.  
  131. filestr        equ    2
  132. maxfilestr    equ    127
  133. filestrloc    equ    $1E01
  134.  
  135. btpathstr    equ    3
  136. maxbtpathstr    equ    64
  137. btpathstrloc    equ    $1E81
  138.  
  139. pathstr        equ    4
  140. maxpathstr    equ    127
  141. pathstrloc    equ    $2007
  142.  
  143. *********************************************
  144.  
  145.         export    intspace
  146. intspace        PROC
  147.         ds.b    256
  148.         endp
  149.  
  150. ******************
  151.  
  152.         export    strspace
  153. strspace        PROC
  154.         export    strlens, maxstrlens, strlocs
  155. strlens        ds.b    numstrings
  156. maxstrlens    dc.b    maxbffrstr, maxtempstr, maxfilestr, maxbtpathstr, maxpathstr
  157. strlocs        dc.w    bffrstrloc, tempstrloc, filestrloc, btpathstrloc, pathstrloc
  158.         endp
  159.  
  160. ******************
  161.  
  162. main        PROC
  163.  
  164.         lda    #0        ;Clear the variable space.
  165.         tax            ;This application does not
  166. @clearvars    sta    intspace,x    ;need to variables to be
  167.         inx            ;pre-cleared.
  168.         bne    @clearvars
  169.  
  170. @moveDisp    lda    $4000,x        ;Move the dispatcher to $2000.
  171.         sta    $2000,x        ;This is so we can use buildapp.system
  172.         lda    $4100,x        ;to build buildapp.system.
  173.         sta    $2100,x
  174.         inx
  175.         bne    @moveDisp
  176.  
  177.         ldx    #64        ;Get boot path from system
  178. @getPath        lda    $2006,x        ;file and place it in btpathstr.
  179.         sta    btFileName,x
  180.         dex
  181.         bpl    @getPath
  182.         lda    btFileName
  183.         sta    strlens+btpathstr
  184.  
  185. ******************
  186.  
  187. restart        lda #0            ;This string is the last read from the
  188.         sta    strlens+bffrstr    ;buildapp.text file.  Init it to NULL.
  189.  
  190.         jsr    $C300        ;Initialize 80-col screen.
  191.         _writecr
  192.         jsr    home
  193.  
  194.         _rtreset
  195.         _hibitchrs
  196.  
  197.         _write    'IIe Application builder  v4.2',13,\
  198.             'Copyright (C) 1990 by Apple Computer.',13,13,\
  199.             'Building application, please wait.',13,13,13
  200.  
  201.         _strcpy    filestr,btpathstr
  202.                     ;Put file name of load build text
  203.                     ;in filestr.  All proDOS operations
  204.                     ;that need a file name expect it in
  205.                     ;filestr in this application.
  206.  
  207.         jsr    loadFile
  208.         dc.w    buildText
  209.         dc.w    $FFFF
  210.         bcc    @a
  211.         _write    13,13,'Could not load '
  212.         _prstr    filestr
  213.         _write    '.'
  214.         jmp    abort
  215.  
  216.  
  217. @a        lda    readBlock+read_transcount
  218.         sta    ptr
  219.         lda    readBlock+read_transcount+1
  220.         clc
  221.         adc    #>buildText    ;Make sure that the build text
  222.         sta    ptr+1        ;ends with a c/r, or else _readstr
  223.         lda    #13        ;may get real unhappy.
  224.         ldy    #0
  225.         sta    (ptr),y
  226.         iny            ;If a string of 1 char (a 255) is read,
  227.         iny            ;then the end of the file was read
  228.         sta    (ptr),y        ;prematurely, and an error will be issued.
  229.         dey
  230.         lda    #255
  231.         sta    (ptr),y
  232.  
  233.  
  234.         _restore #buildText    ;Point readData at buildText.
  235.         _readend #13        ;_readstr will stop at a c/r.
  236.  
  237.         _set    buildaddr,*$2006+65
  238. * The dispatcher has the ending location stored in this address.  Point after
  239. * dispatcher.  We don't have to load the dispatcher, since it is already at
  240. * $2000.  (It was used to launch this application.)
  241.  
  242.         _var    pathstr        ;pathstr location is $2007, so text
  243.         jsr    getstr        ;is read directly into dispatcher.
  244.         bcc    @ok1
  245.         jsr    EOFMessage
  246.         _write    'pathname.'
  247.         jmp    abort
  248.  
  249.  
  250. @ok1        lda    strlens+pathstr
  251.         sta    $2006        ;Make a pascal string out of it.
  252.  
  253. ******************
  254.  
  255. mainloop        _var    mode
  256.         jsr    getint
  257.         bcc    @ok2
  258.         jsr    EOFMessage
  259.         _write    'bank selection bit setting.'
  260.         jmp    abort
  261.  
  262. @ok2        lda    intspace+mode+1    ;Make sure only bit 7 of hi-byte is
  263.         asl    a        ;on, if any.  This bit indicates that
  264.         bne    @bad2        ;GSBUG should be prepped for 8-bit.
  265.         lda    intspace+mode
  266.         and    #$20        ;Make sure bit 5 is off.
  267.         beq    @ok2a
  268. @bad2        _write    'Bad bank selection bit setting ('
  269.         _var    mode
  270.         lda    decimalint
  271.         bne    @bad2a
  272.         _write    '$'
  273.         _vhexout
  274.         jmp    @bad2b
  275. @bad2a        _vdecout
  276. @bad2b        _write    ').'
  277.         jmp    abort
  278.  
  279. @ok2a        _var    address
  280.         jsr    getint
  281.         bcc    @ok3
  282.         jsr    EOFMessage
  283.         lda    intspace+mode
  284.         bpl    @a
  285.         _write    'starting'
  286.         jmp    @b
  287. @a        _write    'segment'
  288. @b        _write    ' address.'
  289.         jmp    abort
  290.  
  291. @ok3        lda    intspace+mode+1    ;Check GSBUG 8-bit prep bit.
  292.         beq    @c
  293.         jmp    prepGSBUG    ;Prep GSBUG to work in 8-bit.
  294.  
  295. @c        lda    intspace+mode    ;Bit 7 of mode byte indicates no
  296.         bpl    @d        ;more segments.  Following field
  297.         jmp    startaddr    ;is launch address.
  298.  
  299. @d        _var    filestr
  300.         jsr    getstr
  301.         bcc    @ok4
  302.         jsr    EOFMessage
  303.         _write    'filename.'
  304.         jmp    abort
  305.  
  306. @ok4        _write 'Loading '
  307.         _prstr filestr
  308.         _write '...',13
  309.  
  310.         lda    intspace+buildaddr ;Make space for 5 bytes that
  311.         clc            ;will be filled in later.
  312.         adc    #5
  313.         sta    @addr
  314.         lda    intspace+buildaddr+1
  315.         adc    #0
  316.         sta    @addr+1
  317.         jsr    loadFile
  318. @addr        dc.w    $2000
  319.         dc.w    $FFFF
  320.         bcc    @e
  321.         jmp    noLoad
  322.  
  323. @e        lda    intspace+buildaddr ;Put the segment relocation
  324.         sta    ptr        ;information in front of segment.
  325.         lda    intspace+buildaddr+1
  326.         sta    ptr+1
  327.         ldy    #0
  328.         lda    intspace+mode
  329.         sta    (ptr),y
  330.         iny
  331.         lda    intspace+address
  332.         sta    (ptr),y
  333.         iny
  334.         lda    intspace+address+1
  335.         sta    (ptr),y
  336.         iny
  337.         lda    readBlock+read_transcount
  338.         sta    (ptr),y
  339.         iny
  340.         lda    readBlock+read_transcount+1
  341.         sta    (ptr),y
  342.  
  343.         lda    ptr        ;Point past segment.
  344.         clc
  345.         adc    #5
  346.         bcc    @f
  347.         inc    ptr+1
  348.         clc
  349. @f        adc    readBlock+read_transcount
  350.         sta    intspace+buildaddr
  351.         lda    ptr+1
  352.         adc    readBlock+read_transcount+1
  353.         sta    intspace+buildaddr+1
  354.  
  355.         jmp    mainloop        ;Load another segment.
  356.  
  357. startaddr    _write    13,'Starting address is '
  358.         _var    tempstr
  359.         jsr    getstr
  360.         bcc    @ok5
  361.         jsr    crEOFMessage
  362.         _write    'address display format.'
  363.         jmp    abort
  364.  
  365. @ok5        lda    tempstrloc
  366.         _var    address
  367.         cmp    #'$'
  368.         beq    @hex
  369.         _vdecout
  370.         jmp    @a
  371. @hex        _rtcout
  372.         _vhexout
  373. @a        _writecr
  374.  
  375.         lda    intspace+buildaddr ;Store the launch information.
  376.         sta    ptr
  377.         lda    intspace+buildaddr+1
  378.         sta    ptr+1
  379.         ldy    #0
  380.         lda    intspace+mode
  381.         sta    (ptr),y
  382.         iny
  383.         lda    intspace+address
  384.         sta    (ptr),y
  385.         iny
  386.         lda    intspace+address+1
  387.         sta    (ptr),y
  388.  
  389.         lda    ptr        ;Calculate application size.
  390.         sec
  391.         sbc    #<$2000-3
  392.         sta    intspace+applen
  393.         lda    ptr+1
  394.         sbc    #>$2000-3
  395.         sta    intspace+applen+1
  396.  
  397.         _write    13,'Application length is '
  398.         _var    tempstr
  399.         jsr    getstr
  400.         bcc    @ok6
  401.         jsr    crEOFMessage
  402.         _write    'length display format.'
  403.         jmp    abort
  404.  
  405. @ok6        lda    tempstrloc
  406.         _var    applen
  407.         cmp    #'$'
  408.         beq @hex0
  409.         _vdecout
  410.         jmp @a0
  411. @hex0        _rtcout
  412.         _vhexout
  413.  
  414. @a0        _write    13,13,'Save application? (Y,N,Q) '
  415.         _var    tempstr        ;See if we have a script value for
  416.         jsr    getstr        ;Y,N,Q.
  417.         ldx    strlens+tempstr
  418.         beq    @b        ;Nothing, so no Y,N,Q script command.
  419.         lda    tempstrloc
  420.         and    #$5F
  421.         cmp    #'Y'
  422.         beq    @b0
  423.         cmp    #'N'
  424.         beq    @b0
  425.         cmp    #'Q'
  426.         beq    @b0        ;Wasn't a Y,N,Q script command.
  427. @b        jsr    rdkey
  428. @b0        and    #$5F
  429.         cmp    #'Y'
  430.         beq    saveit
  431.         cmp    #'N'
  432.         beq    runit
  433.         cmp    #'Q'
  434.         bne    @b
  435.  
  436. quit        jsr    rtcout
  437.         jsr    MLI
  438.         dc.b    QUIT
  439.         dc.w    @parmTable
  440. @parmTable    dc.b    4
  441.         dc.b    0
  442.         dc.w    0
  443.         dc.b    0
  444.         dc.w    0
  445.  
  446. runit        jsr    rtcout
  447.         jmp    $2000
  448.  
  449. saveit        jsr    rtcout
  450.         _var    filetype
  451.         jsr    getint
  452.         bcc    @ok7
  453.         jsr    crEOFMessage
  454.         _write    'filetype.'
  455.         jmp    abort
  456.  
  457. @ok7        _var    auxtype
  458.         jsr    getint
  459.         bcc    @ok8
  460.         jsr    crEOFMessage
  461.         _write    'auxtype.'
  462.         jmp    abort
  463.  
  464. @ok8        _writecr            ;Go ahead and save it.
  465.         _var    filestr
  466.         jsr    getstr
  467.         bcc    @ok9
  468.         jsr    crEOFMessage
  469.         _write    'application filename.'
  470.         jmp    abort
  471.  
  472. @ok9        _write    13,'Saving application as '
  473.         _prstr
  474.         lda    intspace+applen
  475.         sta    @len
  476.         lda    intspace+applen+1
  477.         sta    @len+1
  478.         jsr    saveFile
  479.         dc.w    $2000
  480. @len        dc.w    $FFFF
  481.         bcc @a
  482.         _write    13,13,'Could not save '
  483.         _prstr    filestr
  484.         _write    '.'
  485.         jmp    abort
  486.  
  487. @a        jsr    getFileInfo    ;Update filetype and auxtype.
  488.         bcc    @b
  489.         _write    13,13,'Could not get file info for '
  490.         _prstr    filestr
  491.         _write    '.'
  492.         jmp    abort
  493.  
  494. @b        jsr    getToSet        ;Move getInfo data to setInfo block.
  495.         lda    intspace+filetype    ;Set filetype and auxtype.
  496.         sta    setFileInfoBlock+setInfo_filetype
  497.         lda    intspace+auxtype
  498.         sta    setFileInfoBlock+setInfo_auxtype
  499.         jsr    setFileInfo
  500.         bcc    @c
  501.         _write    13,13,'Could not set file info for '
  502.         _prstr    filestr
  503.         _write    '.'
  504.         jmp    abort
  505.  
  506. @c        jmp    $2000        ;Launch application.
  507.  
  508.  
  509. noLoad        _write    13,13,'Could not load '
  510.         _prstr    filestr
  511.         _write    '.'
  512.  
  513. abort        _write    13,'Please fix and press any key to rebuild ',\
  514.             '(or Q to quit). '
  515.         jsr    rdkey
  516.         and    #$5F
  517.         cmp    #'Q'
  518.         bne    @a
  519.         jmp    quit
  520. @a        jmp    restart
  521.  
  522.  
  523. getstr        txa
  524.         pha
  525.         jsr    fillbffrstr
  526.         pla
  527.         tax
  528.         bcs    @rts
  529. @ok        _strcpy    ,bffrstr
  530.         lda    #0
  531.         sta    strlens+bffrstr
  532.         clc
  533. @rts        rts
  534.  
  535.  
  536. getint        stx    @xreg
  537.         jsr    fillbffrstr    ;Make sure we have something to chew.
  538.         bcs    @exit        ;If we don't, return an error.
  539.  
  540.         _strval    bffrstr        ;Get the value of the string and
  541.         ldx    @xreg        ;put it in the variable.
  542.         _set
  543.         _var    bffrstr
  544.         ldy    #0
  545.         sty    decimalint
  546. @a        tya            ;First skip over -'s.
  547.         _strchr
  548.         iny
  549.         cmp    #'-'
  550.         beq    @a
  551.         cmp    #'$'
  552.         beq    @b
  553.         dec    decimalint    ;It was a decimal integer.
  554. @b        ldy    strvalcount
  555. @c        tya
  556.         cmp    strlens,x
  557.         bcs    @d        ;Ran out of string.
  558.         _strchr
  559.         iny
  560.         cmp    #','
  561.         bne    @c
  562.         tya
  563. @d        _midstrcpy ,bffrstr
  564.         clc            ;All went well.
  565. @exit        ldx    @xreg        ;Restore x-reg.
  566.         rts            ;All done
  567. @xreg        dc.b    0
  568. decimalint    dc.b    0
  569.  
  570.  
  571. fillbffrstr    lda    strlens+bffrstr    ;See if there is any string left.
  572.         beq    @a        ;There is not, so get another.
  573.         clc
  574.         rts            ;There is, so munch away.
  575. @a        _readstr    bffrstr        ;Read in the next.
  576.         jsr    stripComment    ;Chew off comments -- (who needs them?)
  577.         lda    strlens+bffrstr    ;How did we do?
  578.         beq    @a        ;Empty line -- try again.
  579.         lda    bffrstrloc    ;Check for eof marker.
  580.         cmp    #255
  581.         rts            ;Return carry set if eof hit.
  582.  
  583.  
  584. stripComment    txa
  585.         pha
  586.         asl    a
  587.         tax
  588.         lda    strlocs,x    ;Point to the string.
  589.         sta    ptr
  590.         lda    strlocs+1,x
  591.         sta    ptr+1
  592.         pla
  593.         tax
  594.         ldy    #0
  595. @a        tya
  596.         cmp    strlens,x
  597.         beq    @b        ;Hit end-of-string.
  598.         lda    (ptr),y
  599.         iny
  600.         cmp    #';'
  601.         bne    @a        ;Not at comment yet.
  602.         dey
  603.  
  604. @b        dey            ;Remove all trailing white-space.
  605.         bpl    @c        ;Still some characters left.
  606.         lda    #0
  607.         sta    strlens,x    ;Ran out of string.
  608.         rts
  609.  
  610. @c        lda    (ptr),y        ;See if it white-space.
  611.         cmp    #9
  612.         beq    @b        ;If it is, keep backing up.
  613.         cmp    #' '
  614.         beq    @b
  615.         iny            ;We ran into something solid.
  616.         tya
  617.         sta    strlens,x
  618.  
  619. @noComment    rts
  620.  
  621. crEOFMessage    _writecr
  622. EOFMessage    _write 'Build script EOF hit while reading '
  623.         rts
  624.  
  625. prepGSBUG    lda    intspace+address+1
  626.         cmp    #$08
  627.         bcc    @bad
  628.         cmp    #$C0-4-1        ;Save space for GSBUG work area and $BF page.
  629.         bcs    @bad
  630.         lda    intspace+address
  631.         beq    @good
  632. @bad        _write    'Bad GSBUG workspace address ('
  633.         _var    address
  634.         lda    decimalint
  635.         bne    @bada
  636.         _write    '$'
  637.         _vhexout
  638.         jmp    @badb
  639. @bada        _vdecout
  640. @badb        _write    ').'
  641.         jmp    abort
  642.  
  643. @good        clc            ;Turn 16-bit on.
  644.         xce
  645.         rep    #$30
  646.         longi    on
  647.         longa    on
  648.  
  649.         php            ;We don't want others playing
  650.         sei            ;memory games during this.
  651.  
  652.         pha
  653.         pha
  654.         pea    $0800>>16
  655.         pea    $0800
  656.         _FindHandle
  657.         pla
  658.         sta    ptr        ;It is actually a handle.
  659.         pla
  660.         sta    ptr+2
  661.  
  662.         ldy    #4        ;Get handle info for RAM block that
  663.         lda    [ptr],y        ;GS/OS creates to protect primary
  664.         sta    attr        ;memory space.
  665.         iny
  666.         iny
  667.         lda    [ptr],y
  668.         sta    userID
  669.  
  670.         ldx    #0
  671.         phx
  672.         phx
  673.         pei    ptr+2        ;We want to resize and change the
  674.         pei    ptr        ;handle, so purge it first.
  675.         _SetHandleSize
  676.  
  677.         lda    #$C000-$0400    ;Calculate new size for handle.
  678.         sec
  679.         sbc    intspace+address
  680.         ldx    #0
  681.         phx
  682.         pha            ;New size now pushed.
  683.         pei    userID
  684.         pei    attr
  685.         phx
  686.         lda    intspace+address
  687.         clc
  688.         adc    #$0400
  689.         pha            ;New location in memory now pushed.
  690.         pei    ptr+2
  691.         pei    ptr
  692.         _ReAllocHandle
  693.  
  694.         lda    intspace+address
  695.         sec
  696.         sbc    #$0800
  697.         beq    @done        ;We don't need a second handle.
  698.         pha
  699.         pha
  700.         ldx    #0
  701.         phx
  702.         pha            ;Block size now pushed.
  703.         pei    userID
  704.         pei    attr
  705.         phx
  706.         pea    $0800
  707.         _NewHandle
  708.         pla
  709.         pla
  710.  
  711. @done        plp            ;Restore interrupts.
  712.         sec            ;Turn 8-bit back on.
  713.         xce
  714.         longi    off
  715.         longa    off
  716.         jmp    mainloop
  717.  
  718.  
  719. *********************************************
  720.  
  721.  
  722. createFile    jsr    MLI
  723.         dc.b    CREATE
  724.         dc.w    createBlock
  725.         rts
  726. createBlock    dc.b    7
  727.         dc.w    fileName
  728.         dc.b    $C3
  729.         dc.b    $06
  730.         dc.w    $2000
  731.         dc.b    $01
  732.         dc.w    $00
  733.         dc.w    $00
  734.  
  735.  
  736. setFileInfo    jsr    MLI
  737.         dc.b    SETFILEINFO
  738.         dc.w    setFileInfoBlock
  739.         rts
  740. setFileInfoBlock    dc.b    7
  741.         dc.w    fileName
  742.         dc.b    0
  743.         dc.b    0
  744.         dc.w    0
  745.         ds.b     3
  746.         dc.w    0
  747.         dc.w    0
  748.  
  749.  
  750. getFileInfo    jsr    MLI
  751.         dc.b    GETFILEINFO
  752.         dc.w    getFileInfoBlock
  753.         rts
  754. getFileInfoBlock    dc.b    10
  755.         dc.w    fileName
  756.         dc.b    0
  757.         dc.b    0
  758.         dc.w    0
  759.         ds.b    1
  760.         dc.w    1
  761.         dc.w    0
  762.         dc.w    0
  763.         dc.w    0
  764.         dc.w    0
  765.  
  766.  
  767. getToSet        ldy    #13-1
  768. @a        lda    getFileInfoBlock+getInfo_pathname,y
  769.         sta    setFileInfoBlock+getInfo_pathname,y
  770.         dey
  771.         bpl    @a
  772.         rts
  773.  
  774.  
  775. openFile        jsr    MLI
  776.         dc.b    OPEN
  777.         dc.w    openBlock
  778.         ldx    openBlock+open_refnum
  779.         stx    readBlock+read_refnum
  780.         stx    writeBlock+write_refnum
  781.         stx    setEOFBlock+setEOF_refnum
  782.         stx    closeBlock+close_refnum
  783.         rts
  784. openBlock    dc.b    3
  785.         dc.w    fileName
  786.         dc.w    $BF00-1024
  787.         dc.b    1
  788.  
  789.  
  790. readFile        jsr    MLI
  791.         dc.b    READ
  792.         dc.w    readBlock
  793.         rts
  794. readBlock    dc.b    4
  795.         dc.b    1
  796.         dc.w    $2000
  797.         dc.w    $2000
  798.         dc.w    0
  799.  
  800.  
  801. writeFile    jsr    MLI
  802.         dc.b    WRITE
  803.         dc.w    writeBlock
  804.         rts
  805. writeBlock    dc.b    4
  806.         dc.b    1
  807.         dc.w    $2000
  808.         dc.w    $2000
  809.         dc.w    0
  810.  
  811.  
  812. setEOF        jsr    MLI
  813.         dc.b    SETEOF
  814.         dc.w    setEOFBlock
  815.         rts
  816. setEOFBlock    dc.b    2
  817.         dc.b    1
  818.         ds.b    3
  819.  
  820.  
  821. closeFile    jsr    MLI
  822.         dc.b    CLOSE
  823.         dc.w    closeBlock
  824.         rts
  825. closeBlock    dc.b    1
  826.         dc.b    1
  827.  
  828.  
  829. loadFile        pla            ;Set ptr to point to params.
  830.         sta    ptr
  831.         pla
  832.         sta    ptr+1
  833.         jsr    prepFile        ;Get all data ready.
  834.         lda    ptr+1        ;Restore return address.
  835.         pha
  836.         lda    ptr
  837.         pha
  838.         jsr    openFile        ;Try opening the file.
  839.         bcs    @rts        ;Bad news...
  840.         jsr    readFile        ;Try reading the file.
  841.         bcc    @a        ;Good news.
  842.         php            ;Read failed -- try closing the
  843.         pha            ;file and restoring the error
  844.         jsr    closeFile    ;to the read error status.
  845.         pla
  846.         plp
  847.         rts
  848. @a        jsr    closeFile    ;Return result of close.
  849. @rts        rts
  850.  
  851.  
  852. saveFile        pla            ;Set ptr to point to params.
  853.         sta    ptr
  854.         pla
  855.         sta    ptr+1
  856.         jsr    prepFile        ;Get all data ready.
  857.         lda    ptr+1        ;Restore return address.
  858.         pha
  859.         lda    ptr
  860.         pha
  861.         jsr    createFile    ;Try creating file.
  862.         bcc    @a        ;There was no such file.
  863.         cmp    #$47        ;Make sure error is duplicate file error.
  864.         sec
  865.         bne    @rts
  866.  
  867. @a        jsr    openFile        ;Try opening the file.
  868.         bcs    @rts        ;Bad news...
  869.  
  870.         jsr    writeFile    ;Try writing the file.
  871.         bcc    @b        ;Good news.
  872.         php            ;Write failed -- try closing the
  873.         pha            ;file and restoring the error
  874.         jsr    closeFile    ;to the write error status.
  875.         pla
  876.         plp
  877.         rts
  878.  
  879. @b        lda    writeBlock+write_reqcount
  880.         sta    setEOFBlock+setEOF_EOF
  881.         lda    writeBlock+write_reqcount+1
  882.         sta    setEOFBlock+setEOF_EOF+1
  883.         lda    #0
  884.         sta    setEOFBlock+setEOF_EOF+2
  885.         jsr    setEOF
  886.         bcc    @c
  887.         php
  888.         pha
  889.         jsr    closeFile
  890.         pla
  891.         plp
  892.         rts
  893.  
  894. @c        jsr    closeFile    ;Return result of close.
  895. @rts        rts
  896.  
  897.  
  898. prepFile        lda    strlens+filestr
  899.         sta    fileName        ;Length of string.
  900.         ldy    #1
  901.         lda    (ptr),y
  902.         sta    readBlock+read_databuffer
  903.         sta    writeBlock+write_databuffer
  904.         iny
  905.         lda    (ptr),y
  906.         sta    readBlock+read_databuffer+1
  907.         sta    writeBlock+write_databuffer+1
  908.         iny
  909.         lda    (ptr),y
  910.         sta    readBlock+read_reqcount
  911.         sta    writeBlock+write_reqcount
  912.         iny
  913.         lda    (ptr),y
  914.         sta    readBlock+read_reqcount+1
  915.         sta    writeBlock+write_reqcount+1
  916.         tya
  917.         clc
  918.         adc    ptr
  919.         sta    ptr
  920.         bcc    @d
  921.         inc    ptr+1
  922. @d        rts
  923.  
  924.         endp
  925.  
  926.         END
  927.